package net.siufung.market.base.app.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;
import net.siufung.core.model.EnumsVo;
import net.siufung.core.model.IEnum;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 陈建峰
 * @date 2023/2/2 4:26 PM
 * @since V1.0.0
 */
@ToString
@AllArgsConstructor
public enum GrantTypes implements IEnum<String> {

    /**
     * 内部应用
     */
    CLIENT_CREDENTIALS("client_credentials", "客户端模式"),

    /**
     * 第三方应用
     */
    AUTHORIZATION_CODE("authorization_code", "授权码模式"),
    /**
     * 密码模式
     */
    PASSWD("passwd", "密码模式"),
    /**
     * UUC密码模式
     */
    UUC_PASSWD("uuc_passwd", "UUC密码模式");

    @Getter
    private final String value;

    @Getter
    private final String text;


    public static GrantTypes get(String value) {
        return IEnum.get(GrantTypes.class,
                enums -> enums.getValue().equals(value));
    }

    public static String getDesc(String value) {
        return IEnum.getDesc(GrantTypes.class,
                enums -> enums.getValue().equals(value));
    }

    public static List<EnumsVo> getList(){
        return IEnum.findList(GrantTypes.class).stream()
                .map(element -> new EnumsVo(element.getValue(), element.getDesc(), element.getText()))
                .collect(Collectors.toList());
    }
}
